package com.hr.controller.admin;

import com.hr.domain.dto.HouseFacilityDTO;
import com.hr.domain.po.HouseFacility;
import com.hr.domain.query.HouseFacilityPageParams;
import com.hr.domain.query.HouseFacilityPageResult;
import com.hr.domain.vo.HouseFacilityVO;
import com.hr.service.HouseFacilityService;
import com.hr.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin")
@Tag(name = "后台房屋周边配套信息管理")
@AllArgsConstructor
public class HouseFacilityController {

    private final HouseFacilityService houseFacilityService;

    /**
     * 获取房屋周边配套信息列表
     * @return houseFacilityList
     */
    @GetMapping("/house/facility/list")
    @Operation(summary = "获取房屋周边配套信息列表")
    public Result getHouseFacilityList() {
        log.info("获取房屋周边配套信息列表");
        List<HouseFacilityVO> houseFacilityList = houseFacilityService.getHouseFacilityList();
        if (houseFacilityList == null){
            return Result.error("没有房屋周边配套信息");
        }
        return Result.success(houseFacilityList);
    }

    /**
     * 分页获取房屋周边配套信息列表
     * @param queryParams
     * @return houseFacilityPageResult
     */
    @GetMapping("/house/facility/page")
    @Operation(summary = "分页获取房屋周边配套信息列表")
    public Result getHouseFacilityPageList(HouseFacilityPageParams queryParams) {
        log.info("分页获取房屋周边配套信息列表");
        HouseFacilityPageResult houseFacilityPageResult = houseFacilityService.getHouseFacilityPageList(queryParams);
        return Result.success(houseFacilityPageResult);
    }
    /**
     * 获取房屋周边配套信息类型
     * @return houseFacilityType
     */
    @GetMapping("/house/facility/facilityType")
    @Operation(summary = "获取房屋周边配套信息类型")
    public Result getHouseFacilityType() {
        log.info("获取房屋周边配套信息类型");
        List<String> houseFacilityType = houseFacilityService.getHouseFacilityType();
        return Result.success(houseFacilityType);
    }

    /**
     * 添加房屋周边配套信息
     * @param houseFacilitydto
     * @return msg
     */
    @PostMapping("/house/facility/add")
    @Operation(summary = "添加房屋周边配套信息")
    public Result addHouseFacility(@RequestBody HouseFacilityDTO houseFacilitydto) {
        if(houseFacilitydto.getHouseId() == null){
            return Result.error("请传入房屋ID");
        }
        log.info("添加房屋周边配套信息");
        String msg = houseFacilityService.addHouseFacility(houseFacilitydto);
        return Result.success(msg);
    }

    /**
     * 删除房屋周边配套信息
     * @param id
     * @return msg
     */
    @DeleteMapping("/house/facility/delete/{id}")
    @Operation(summary = "删除房屋周边配套信息")
    public Result deleteHouseFacility(@PathVariable("id") Integer id) {
        log.info("删除房屋周边配套信息");
        String msg = houseFacilityService.deleteHouseFacility(id);
        return Result.success(msg);
    }
    /**
     * 获取单个房屋周边配套信息
     * @param id
     * @return
     */
    @GetMapping("/house/facility/detail/{id}")
    @Operation(summary = "获取单个房屋周边配套信息")
    public Result getHouseFacility(@PathVariable("id") Integer id) {
        log.info("获取单个房屋周边配套信息");
        HouseFacilityVO houseFacility = houseFacilityService.getHouseFacility(id);
        if (houseFacility == null){
            return Result.error("没有该周边配套信息");
        }
        return Result.success(houseFacility);
    }

    /**
     * 批量删除房屋周边配套信息
     * @param ids
     */
    @DeleteMapping("/house/facility/deleteBatch")
    @Operation(summary = "批量删除房屋周边配套信息")
    public Result deleteHouseFacilityBatch(@RequestBody List<Integer> ids) {
        log.info("批量删除房屋周边配套信息");
        String msg = houseFacilityService.deleteHouseFacilityBatch(ids);
        return Result.success(msg);
    }


    /**
     * 更新房屋周边配套信息
     * @param houseFacilitydto
     * @return msg
     */
    @PutMapping("/house/facility/update")
    @Operation(summary = "更新房屋周边配套信息")
    public Result updateHouseFacility(@RequestBody HouseFacilityDTO houseFacilitydto) {
        if(houseFacilitydto.getId() == null){
            return Result.error("请传入周边配套信息ID");
        }
        log.info("更新房屋周边配套信息");
        String msg = houseFacilityService.updateHouseFacility(houseFacilitydto);
        return Result.success(msg);
    }


}
